package com.hxj.docking.service;

import com.hxj.docking.pojo.dto.DataDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @Author hxj
 * @Date 2024/11/21 19:59
 * @Description
 */

@Component
@Slf4j
public class AsyncTask {

    @Async("myThreadPool")
    public void processDataAsync(DataDTO dataDTO) throws InterruptedException {
        log.info("进入线程：" + dataDTO.getNo());

        synchronized (dataDTO.getHead()) {
            // 在线程内部加锁生成编号
            log.info("进入synchronized块：" + dataDTO.getNo() + " " + dataDTO.getHead());
            Thread.sleep(5000);

        }
        log.info("退出线程：" + dataDTO.getNo());
    }

}
